package com.weyoung.app.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weyoung.app.mapper.AccessStatsMapper;
import com.weyoung.app.service.AccessStatsService;
import com.weyoung.entity.AccessStats;
import org.springframework.stereotype.Service;

@Service
public class AccessStatsServiceImpl extends ServiceImpl<AccessStatsMapper, AccessStats> implements AccessStatsService {
    
    @Override
    public void saveOrUpdateStats(AccessStats stats) {
        LambdaQueryWrapper<AccessStats> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AccessStats::getUrl, stats.getUrl())
                .eq(AccessStats::getUserId, stats.getUserId())
                .eq(AccessStats::getDate, stats.getDate());
        
        AccessStats existing = this.getOne(wrapper);
        if (existing == null) {
            this.save(stats);
        } else {
            existing.setPv(existing.getPv() + 1);
            this.updateById(existing);
        }
    }
} 